package com.sj.purchase.modules.cost.web;

import com.sj.purchase.modules.cost.service.order.OutOrderService;
import com.sj.purchase.modules.cost.views.order.OutOrderVO;
import com.sj.purchase.util.ExcelDownloadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.stream.Collectors;

/**
 * Created by Alin on 2017/11/15.
 */
@RestController
@RequestMapping("api/order/cost/price")
public class OrderCostPriceController {
    @Autowired
    private OutOrderService outOrderService;

    @GetMapping("/list")
    private ResponseEntity getList(String orderNo, Date startDate, Date endDate, Pageable pageable){
        try {
            return ResponseEntity.ok(outOrderService.findAll(startDate,endDate,orderNo,pageable));
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseEntity.ok("");
    }

    @GetMapping("/excel")
    private void excel(String orderNo,Date startDate,Date endDate){
        ExcelDownloadUtil.easyPoi("订单成本", OutOrderVO.class,outOrderService.findAll(startDate,endDate,orderNo,null).getContent().stream().collect(Collectors.toList()));
    }


}
